package com.wx.mock;

import cn.hutool.core.util.IdUtil;
import com.forte.util.Mock;
import com.forte.util.mockbean.MockObject;
import lombok.extern.slf4j.Slf4j;

import java.security.SecureRandom;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 模拟预警任务
 *
 * @author wang.xun
 * @date 2022/12/20
 */
@Slf4j

public class MockAlarmTask {
    static {
        Map<String, Object> map = new HashMap<>();
        map.put("id", IdUtil.getSnowflake(1,1).nextId());
        // 抓拍时间
        map.put("captureTime", "@date");
        // 预警类型
        map.put("alarmType", new String[]{"01","02","03","04"});
        // 预警时间
        map.put("alarmTime", new Date());
        // 车牌
        map.put("plateNo", carNumber());

        // 车辆类型 1-15
        map.put("plateType", "@integer(1,14)");

        // 车辆颜色 1-15
        map.put("vehicleBrand", "@integer(1,343)");
        // 车辆颜色 1-15
        map.put("vehicleColor", "@integer(1,15)");

        map.put("createTime", new Date());

        Mock.set(TbBizYzAlarm.class , map);
    }


    public static void main(String[] args) {

        MockObject<TbBizYzAlarm> mockObject = Mock.get(TbBizYzAlarm.class);
        List<TbBizYzAlarm> list = mockObject.getList(10);

        list.forEach(System.out::println);
    }




    //车牌号码
    public static String carNumber() {
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("京");
        for (int i = 0; i < 3; i++)
            stringBuffer.append(character());
        for (int i = 0; i < 4; i++)
            stringBuffer.append(number());

        return stringBuffer.toString();
    }

    //随机大写字母（'A' - 'Z'）
    public static char character() {
        return (char)(new SecureRandom().nextInt('Z' - 'A') + 'A');
    }

    //随机数字（0 - 9）
    public static int number() {
        return (int)(Math.random() * 10);
    }


}
